// pages/userStatistics/UserDeatils/vipBean.js
const controller=require("../../controllers/Controller").controller
const controllers=require("../../controllers/controllerIndex").controller

Page({

  /**
   * 页面的初始数据
   */
  data: {
    bean:"",
    totalbean:"",
    tabList:[
      {
        name:'收益记录',
        type:0
      },
      {
        name:'股东提现申请',
        type:1
      }
    ],
    selectIndex:0,
    pageNumber:1,
    amountList:[],
    userMsg:""
  },

  //跳转详情
  toGoldDetail(e){
    let orderNo=e.currentTarget.dataset.orderno
    let genre=e.currentTarget.dataset.genre
    let type=e.currentTarget.dataset.type
    let name=e.currentTarget.dataset.name
    let head=e.currentTarget.dataset.head
    let accountId=e.currentTarget.dataset.accountid
  
    wx.navigateTo({
      url: '/pages/Index/transactionRecord/transactionDetails?orderNo='+orderNo+"&genre="+genre+"&type="+type+"&name="+name+"&head="+head+"&accountId="+accountId,
    })
  },

  //获取用户数据
  getUserMsg(){
    controllers.accountDetail(
      {
        accountRelationId:this.data.shopRelId,
        shopId:wx.getStorageSync('shopId')
      }
    ).then(res =>{
      this.setData({
        userMsg:res.data
      })
    })
  },

  //跳转提现详情
  toDetail(e){
    let index=e.currentTarget.dataset.index
    let msg=encodeURIComponent(JSON.stringify(this.data.amountList[index]))
    wx.navigateTo({
      url: '/pages/Index/shareholderManage/cashOutDetail?msg='+msg,
    })
  },

  //获取提现记录
  getCashOutHistory(){
    let value={}
    value.type=1
    value.pageNumber=this.data.pageNumber
    value.shopId=wx.getStorageSync('shopId')
    value.accountId=this.data.id
    controller.getCashHistory(value).then(res=>{
      this.setData({
        amountList:res.data.list,
        lastPage:res.data.lastPage
      })
    })
  },

  //获取金币账单
  getBeanPage(){
    let value={}
    value.pageNumber=this.data.pageNumber
    value.shopId=wx.getStorageSync('shopId')
    value.accountId=this.data.id
    controller.beanPage(value).then(res=>{
      this.setData({
        amountList:res.data.list,
        lastPage:res.data.lastPage
      })
    })
  },

  changeType(e){
    this.setData({
      selectIndex:e.currentTarget.dataset.index,
      pageNumber:1
    })
    if(this.data.selectIndex==0){
      this.getBeanPage()
    }else{
      this.getCashOutHistory()
    }
  },

  getMore(){
    if(this.data.lastPage==false){
      if(this.data.selectIndex==0){
        let value={}
        value.pageNumber=this.data.pageNumber
        value.shopId=wx.getStorageSync('shopId')
    
        controller.beanPage(value).then(res=>{
          let list=this.data.amountList
          let list2=res.data.list
          let list3=list.concat(list2)
          this.setData({
            amountList:list3,
            lastPage:res.data.lastPage
          })
        })
      }else{
        let value={}
        value.pageNumber=this.data.pageNumber
        value.type=1
    
        controller.getCashHistory(value).then(res=>{
          let list=this.data.amountList
          let list2=res.data.list
          let list3=list.concat(list2)
          this.setData({
            amountList:list3,
            lastPage:res.data.lastPage
          })
        })
      }
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id:options.id,
      shopRelId:options.shopRelId
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getUserMsg()
    if(this.data.selectIndex==0){
      this.getBeanPage()
    }else{
      this.getCashOutHistory()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getMore()
  }, 

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})